<template>
    <el-select
        v-model="chooseStore"
        placeholder="根据门店名称搜索选择门店"
        style="width: 400px"
        filterable
		clearable
		@change="sendData"
        :remote="true"
        :remote-method="searchStoreList"
        :loading="storeLoading"
        reserve-keyword
        loading-text="加载中。。。"
        ref="storeRef"
        class="store-select"
        value-key="id"
		:disabled="isOwnerId"
	>
		<el-option
			v-for="item in storeList"
			:key="item.id"
			:label="item.name"
			:value="item.id"
		>
		</el-option>
	</el-select>
</template>

<script>
import {GetContractableSellers,GetContractableBuyers} from '@/api/article.js'
export default {
	data(){
		return {
			chooseStore:'',
			storeList:[],
			storeLoading:false,
			isOwnerId:false,
		}
	},
	props:{
		ownerId:false,
		storeType:'',
		alertId:'',
		initData:''
	},
	created(){
		console.log(this.initData);
		// this.storeList = _.cloneDeep(this.initData);
		if(this.initData != ''){
			this.storeList.push(this.initData);
			this.chooseStore = this.initData.id;
		}
		if(this.ownerId){
			this.isOwnerId = false;
		}else{
			this.isOwnerId = true;
		}
	},
	methods:{
		async searchStoreList(name){
			this.storeLoading =true;
			let params = {
				pageIndex:1,
				pageSize:100,
				BrandOwnerId:this.ownerId,
				name:name
			}
			if(this.storeType == 'buy'){
				params.SellerId = this.alertId;
				const res = await GetContractableBuyers(params);
				console.log(res);
				this.storeLoading =false;
				if(res.code === 200){
					this.storeList = res.data.list;
				}else{
					this.storeList = [];
				}
			}else{
				params.BuyerId = this.alertId;
				const res = await GetContractableSellers(params);
				console.log(res);
				this.storeLoading =false;
				if(res.code === 200){
					this.storeList = res.data.list;
				}else{
					this.storeList = [];
				}
			}
		},
		sendData(){
			if(this.storeType == 'buy'){
				this.$emit('sendBuyer',this.chooseStore)
			}else{
				this.$emit('sendSaller',this.chooseStore)
			}

		},
	}
}
</script>

<style>

</style>